package com.mes.service;

import com.mes.model.Orders;
import com.mes.repository.OrderRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderService {

    @Autowired
    private OrderRepository orderRepository;

    public List<Orders> getAllOrders() {
        return orderRepository.findAll();
    }

    public Orders createOrder(Orders order) {
        order.setStatus("Pending");
        return orderRepository.save(order);
    }

    public Orders updateOrderStatus(Long id, String status) {
        Orders order = orderRepository.findById(id).orElseThrow(() -> new IllegalArgumentException("Order with id " + id + " not found"));
        order.setStatus(status);
        return orderRepository.save(order);
    }
}
